import 'package:ca_dsp_pro/src/tool/assets.dart';
import 'package:flutter_kit_dsp/flutter_kit_dsp.dart';

class UnitTool extends StatefulWidget {
  List<ChannelModel> chlist;
  List<GroupModel> grouplist;
  void Function(ChannelModel) onTouch;
  void Function(int) onLink;
  UnitTool({super.key, required this.chlist, required this.grouplist, required this.onTouch, required this.onLink});

  @override
  State<UnitTool> createState() => _UnitToolState();
}

class _UnitToolState extends State<UnitTool> {
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.only(left: 5, top: 0, bottom: 5, right: 0),
      color: Color_bg_view,
      child: Column(
        spacing: 5,
        children: [
          Flexible(
              child: Row(
            spacing: 5,
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: widget.chlist.map(($0) {
              return Expanded(
                child: Container(
                  color: $0.select ? Color($0.hex_line) : Color_bg_view2,
                  child: Material(
                    color: Colors.transparent,
                    child: InkWell(
                      onTap: () => widget.onTouch($0),
                      child: Center(child: Text($0.name)),
                    ),
                  ),
                ),
              );
            }).toList(),
          )),
          Flexible(
              child: Row(
            spacing: 5,
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: List.generate((widget.grouplist.length).toInt(), (index) {
              final group = widget.grouplist[index];
              return Expanded(
                child: Container(
                  color: group.select ? Color(group.ch1!.hex_line) : Color_bg_view2,
                  child: Material(
                    color: Colors.transparent,
                    child: InkWell(
                      onTap: () => widget.onLink(index),
                      child: const Center(
                        child: FittedBox(
                          fit: BoxFit.scaleDown,
                          child: Text('LINK',
                              style: TextStyle(fontSize: 20, color: Colors.white, fontWeight: FontWeight.bold)),
                        ),
                      ),
                    ),
                  ),
                ),
              );
            }).toList(),
          ))
        ],
      ),
    );
  }
}
